package com.example.pmqt.common;

import lombok.Data;

@Data
public class ReturnResult {
    // 状态码
    private int code;
    // 消息
    private String msg;
    // 数据
    private Object data;

    private ReturnResult(){

    }

    private static ReturnResult buildResult(int code, String msg, Object data) {
        ReturnResult result = new ReturnResult();
        result.code = code;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static ReturnResult buildSuccessResult(String msg, Object data) {
        return buildResult(200, msg, data);
    }

    public static ReturnResult buildSuccessResult(Object data) {
        return buildSuccessResult("success", data);
    }

    public static ReturnResult buildFailureResult(int code, String msg, Object data) {
        return buildResult(code, msg, data);
    }

    public static ReturnResult buildFailureResult(String msg, Object data) {
        return buildFailureResult(500, msg, data);
    }

    public static ReturnResult buildFailureResult(String msg) {
        return buildFailureResult(500, msg, null);
    }
}
